package com.mtgdeckbuilder.shared;

/**
 * A utility class for string manipulation.
 * 
 * @author Nicolas Deslandes
 */
public class StringUtil {

   /**
    * To hide the default constructor as this class has not to be instantiated.
    */
   private StringUtil() {

   }

   /**
    * Return the occurrence of a string in a text.
    * 
    * @param text the text.
    * @param string the string to check.
    * @return the occurrence of the string in the text.
    */
   public static int stringOccur(final String text, final String string) {
      int occurence = 0;
      int index = text.indexOf(string, 0);
      while (index != -1) {
         index = text.indexOf(string, index);
         occurence++;
      }
      return occurence;
   }

   /**
    * Whether the string passed in parameter is numeric
    * 
    * @param string the string
    * @return true if the string is numeric; otherwise false
    */
   public static boolean isNumeric(final String string) {
      try {
         Integer.parseInt(string);
         return true;
      } catch (final NumberFormatException e) {
         return false;
      }
   }

}
